define(['./../initial', './../model/project'], function() {
    var app = angular.module('App.home');
    app.config(['$stateProvider', '$urlRouterProvider', '$locationProvider',
        function($stateProvider, $urlRouterProvider, $locationProvider) {
            $locationProvider.html5Mode(true);
            // For any unmatched url, redirect to /state1
            $urlRouterProvider.otherwise("/");
            //
            $urlRouterProvider.when('/', ['$stateParams', '$state', 'Project', function($stateParams, $state, Project) {
                Project.getAllProjects().then(function() {
                    $state.go('project.detail.info', {
                        prjId: Project.prjs[0].prjId
                    });
                });
            }]);

            // Now set up the states
            $stateProvider
                .state('project', {
                    resolve: {
                        allProjects: ["Project", function(Project) {
                            return Project.getAllProjects();
                        }]
                    },
                    abstract: true,
                    url: "/project",
                    templateUrl: "/partials/project/project.html",
                    controller: 'homeCtrl'
                })
                .state('project.detail', {
                    url: "/{prjId:[0-9]+}",
                    abstract: true,
                    resolve: {
                        curPrj: ['$stateParams', 'allProjects', '$rootScope',
                            function($stateParams, allProjects, $rootScope) {
                                return allProjects.filter(function(item) {
                                    return item.prjId === parseInt($stateParams.prjId, 0);
                                })[0];
                            }
                        ]
                    },
                    templateUrl: '/partials/project/project.detail.html'
                })
                .state('project.detail.daily', {
                    url: "/daily",
                    templateUrl: "/partials/project/project.detail.daily.html",
                    controller: 'dailyCtrl'
                })
                .state('project.detail.info', {
                    url: "/info",
                    templateUrl: "/partials/project/project.detail.info.html",
                    controller: 'detailCtrl'
                })
                .state('project.detail.map', {
                    url: "/more",
                    templateUrl: "/partials/project/project.detail.map.html",
                    controller: 'mapCtrl'
                });
        }
    ]);



});
